﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SocketClient
{
    /// <summary>
    /// Interaction logic for Resultado.xaml
    /// </summary>
    public partial class Resultado : Window
    {
        private String sala = "";
        private String dono = "";
        private Conexao conexao;
        List<Label> labelList = new List<Label>();
        List<String> jogadores = new List<String>();
        List<String> ranking = new List<String>();

        public Resultado(Conexao con, String dono, String nomeSala)
        {
            this.conexao = con;
            this.dono = dono;
            sala = nomeSala;

            InitializeComponent();

            conexao.Send("exibircolocacao/" + sala);
            String message = conexao.Receive();
            String[] tokens = message.Split('{');

            for (int i = 0; i < tokens.Length; i++)
            {
                String[] tokens1 = tokens[i].Split('|');
                jogadores.Add(tokens1[0]);
                ranking.Add(tokens1[1]);
            }

            int altura = 12;

            for (int i = 0; i < jogadores.Count; i++)
            {
                int posicao = i + 1;
                Label ponto = new Label();
                ponto.Content = posicao.ToString() + "º lugar: " + jogadores[i] + " com " + ranking[i] + " pontos.";
                ponto.FontSize = 17;
                ponto.Height = 33;
                ponto.HorizontalAlignment = HorizontalAlignment.Left;
                ponto.VerticalAlignment = VerticalAlignment.Top;
                ponto.Margin = new Thickness(12, altura, 0, 0);
                gridinha.Children.Add(ponto);
                altura += 26;
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            salinha s = new salinha(conexao, dono, sala);
            Close();
            s.ShowDialog();
        }
    }
}
